Workforce Planning (Matrix Form)

Expression form: $$ \begin{array}{rll} \displaystyle \min_{x\in \mathbb{R}^7} & x_1 + x_2 + x_3 + x_4 + x_5 + x_6 + x_7 \\ \,{\rm s.t.} & \begin{array}[t]{rcl} x_1 + x_4 + x_5 + x_6 + x_7 & \geq & 14 \\ x_1 + x_2 + x_5 + x_6 + x_7 & \geq & 13 \\ x_1 + x_2 + x_3 + x_6 + x_7 & \geq & 15 \\ x_1 + x_2 + x_3 + x_4 + x_7 & \geq & 16 \\ x_1 + x_2 + x_3 + x_4 + x_5 & \geq & 19 \\ x_2 + x_3 + x_4 + x_5 + x_6 & \geq & 18 \\ x_3 + x_4 + x_5 + x_6 + x_7 & \geq & 11 \\ x_i & \geq & 0 ~~~~ \forall ~i \end{array} \end{array} $$


In [1]:
import numpy as np
from scipy.optimize import linprog

Matrix form: $$ \begin{array}{rll} \displaystyle \min_{x\in \mathbb{R}^7} & c^T x \\ \,{\rm s.t.} & \begin{array}[t]{rcl} A\_ub \cdot x & \leq & b\_ub \\ A\_eq \cdot x & = & b\_eq \end{array} \end{array} $$


In [2]:
A_ub = np.array([
[-1,  0,  0, -1, -1, -1, -1],
[-1, -1,  0,  0, -1, -1, -1],
[-1, -1, -1,  0,  0, -1, -1],
[-1, -1, -1, -1,  0,  0, -1],
[-1, -1, -1, -1, -1,  0,  0],
[ 0, -1, -1, -1, -1, -1,  0],
[ 0,  0, -1, -1, -1, -1, -1]])

b_ub = np.array([-14, -13, -15, -16, -19, -18, -11])

c = np.array([1, 1, 1, 1, 1, 1, 1])

res = linprog(c, A_eq=None, b_eq=None, A_ub=A_ub, b_ub=b_ub, 
              bounds=(0, None), method='simplex')

In [11]:
print ("Optimal value: %.2f" % res.fun)
print ('x:', res.x)


Optimal value: 22.00
('x:', array([ 4.,  7.,  1.,  4.,  3.,  3.,  0.]))

In [12]:
sum(res.x)


Out[12]:
22.0

In [13]:
np.dot(-A_ub,res.x)


Out[13]:
array([ 14.,  17.,  15.,  16.,  19.,  18.,  11.])